#include "recvthread.h"
#include <qDebug>

RecvThread::RecvThread(QObject *parent) : QThread(parent)
{
    m_quit = false;
}

RecvThread::~RecvThread(){
    m_quit = true;
}

void RecvThread::runStart(QSerialPort *port){
    m_SerialPort = port;
    m_quit = false;
    if (!isRunning()){
        start();
    }
}

void RecvThread::runStop(){
    m_quit = true;
    wait();
}

void RecvThread::run(){
    qDebug() << "enter run";
    while(!m_quit){
        if (m_SerialPort->waitForReadyRead(10)){
            QByteArray data = m_SerialPort->readAll();
            recvRequest(QString::fromUtf8(data));
        }
    }
}
